import sys
sys.path.append('..\\..')
from Djoser import *
from Tkinter import *

#~ from djwindow import *
main = DjWindow(Tk())

f1 = Frame(main.basecontrol)
f1.pack()

retain = {} #for keeping references.

def test(n):
	if n==1:
		def new(): print 'new'
		def open(): print 'open'
		def quit(): print 'quit'
		def checktoggle(): 
			print 'state:',m.get_menuitem_checked('TOGGLE')
		
		m = DjMenu(main,
			['File',
				'&New Document|Ctrl+N|NEW',new,
				'Open Document|Ctrl+O|OPEN', open,
				['Submenu',
					'To&ggle||TOGGLE|checkbox',None,
					'Check State',checktoggle
				],
				'_',
				'Quit|Alt+F4', quit
			],
			['Edit',
				'Undo', None,
			]
		)
		
		main.menubar = m
	elif n==2:
		if not main.menubar: test(1)
		print 'These do not seem to have effect in Windows.'
		main.menubar.selectioncolor = (255,0,0)
		main.menubar.bgcolor = (0,0,0)
		main.menubar.color = (255,0,0)
		main.menubar.font = ('Times New Roman', 12, 'normal')
		main.menubar.borderwidth = 10
		assert str(main.menubar.borderwidth) == '10'
		main.menubar.borderstyle = 'raised'
	elif n==3:
		if not main.menubar: test(1)
		img1 = PhotoImage(format='gif', data='R0lGODlhGAAYAIABAAAAAP///yH5BAEAAAEALAAAAAAYABgAAAI0jI+py+0PAXxATlbtTVlv03lbKE5kSZ3fWY0surxtRH5BduMuqF9eZzsAg7xZcEg0EpebAgA7')
		retain['img'] = img1 #Keep a reference to the image so it isn't destroyed.
		main.menubar.set_menuitem_property('NEW','image',img1)
		
		# Disable menuitem
		main.menubar.disable_menuitem('OPEN')
	elif n==4:
		if not main.menubar: test(1)
		main.menubar.set_menuitem_checked('TOGGLE',1)
		assert main.menubar.get_menuitem_checked('TOGGLE')
		
	elif n==20:
		def new(): print 'new'
		def open(): print 'open'
		m = DjMenu(main,
				'New',new,
				'Open Document|Ctrl+O|OPEN', open,
			)
		m.set_contextual(testContextual)
		print 'Now right click on the button that says right-click here.'
		
Button(f1,text='Test Menu',command=lambda:test(1)).pack(side=LEFT)
Button(f1,text='Colors',command=lambda:test(2)).pack(side=LEFT)
Button(f1,text='Items',command=lambda:test(3)).pack(side=LEFT)
Button(f1,text='Set toggle',command=lambda:test(4)).pack(side=LEFT)

f2 = Frame(main.basecontrol)
f2.pack()
Button(f2,text='Contextual',command=lambda:test(20)).pack(side=LEFT)
testContextual = Button(f2,text='Right-click here')
testContextual.pack(side=LEFT)

f1.mainloop()
